package cn.com.cetccst.appstore.jssdk;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;

import cn.com.cetccst.appstore.jssdk.viewmodel.JSSDKViewModel;
import cn.com.cetccst.appstore.tools.Utils;


public class ActionCancelDownloadFile extends BaseJSAction<ActionCancelDownloadFile.RequestPara, String> {
    public static final String ACTION = "cancelDownloadFile";

    private JSSDKViewModel viewModel;

    ActionCancelDownloadFile(Context context, CXApiImplInnerApp icxapi, String parameters, JSSDKViewModel jssdkViewModel) {
        super(context, icxapi, parameters);
        this.viewModel = jssdkViewModel;
    }

    @Override
    public void handleAction(Response callback) {
        if (!checkBaseArgs(callback)) {
            return;
        }
        if (!TextUtils.isEmpty(para.tag)) {
            viewModel.removeDownloadTask(para.tag);
            viewModel.removeDownloadFile(para.tag, true);
        }
        callback.setRespJson(buildSuccessResp(""));
    }

    @Override
    protected RequestPara parserParameters(String para) {
        return Utils.getGson().fromJson(para, RequestPara.class);
    }

    @Override
    protected String buildSuccessResp(String result) {
        Resp<RespData> resp = new Resp();
        resp.code = 0;
        resp.data = new RespData();
        return Utils.getGson().toJson(resp);
    }

    static class RequestPara {
        @SerializedName("tag")
        String tag;
    }

    static class RespData {

    }
}
